package LeetCode;

public class LC_476_NumberComplement {

    public static void main(String[] args) {

    }

    class Solution {
        public int findComplement(int num) {
            return ~num & ((Integer.highestOneBit(num) << 1) - 1);
        }
    }

    class Solution_2 {
        public int findComplement(int num) {
            int valid = 0;
            int tmp = num;
            while (tmp > 0) {
                tmp /= 2;
                valid++;
            }
            return ~num & ((1 << valid) - 1);
        }

    }
}